package com.google.code.yargon.level;

import static com.google.code.yargon.util.Constants.*;

/* 
 * Door block
 */
public class DoorBlock extends Block {
	
	private static final long serialVersionUID = 4978840099973775498L;
	
	private int alignment;
	private boolean isOpen = false;
	private boolean isConnectable = false;
	private Direction direction;
	
	public DoorBlock(boolean isOpen, boolean isConnectable, Direction direction) {
		setChar('+');
		this.isOpen = isOpen;
		this.isConnectable = isConnectable;
		this.direction = direction;
		
		if(direction.getDirection() == NORTH || direction.getDirection() == SOUTH) {
			this.alignment = HORIZONTAL;
		} else {
			this.alignment = VERTICAL;
		}
	}
		
	/**
	 * Is the door open?
	 * @return
	 */
	public boolean isOpen() {
		return this.isOpen;
	}

	/**
	 * Open the door
	 * 
	 */
	public void open() {
		this.isOpen = true;
	}
	
	/**
	 * Close the door
	 * 
	 */
	public void close() {
		this.isOpen = false;
	}
	
	/**
	 * Is the door in a place where it can be connected with a tunnel? Requirement is that the block the door faces, is free
	 * This is meaningful only during initial door creation phase.
	 * 
	 * @return
	 */
	public boolean isConnectable() {
		return this.isConnectable;
	}
	
	/**
	 * Which way the door opens (outwards from the room)
	 * 
	 * @return
	 */
	public Direction getDirection() {
		return this.direction;
	}

	/**
	 * Vertical or horizontal door
	 * 
	 * @return
	 */
	public int getAlignment() {
		return this.alignment;
	}
	
	/**
	 * Return door data as a string
	 * 
	 */
	public String toString() {
		return getLocation().toString()+" facing: "+direction;
	}
}
